# Replication script Onderco & Joosen - DIMENSIONALITY OF PARTY POLITICS OF FOREIGN POLICY: INSIGHTS FROM SPATIAL MODELLING
# joosen@essb.eur.nl 08-01-2021
# Script to replicate Figure 1

# Required packages
library(ggplot2)
library(ggpubr)

# Figure 1 ----


#  plot in black and white 

plot_result_per3 <- ggplot(data = data_result_per3, aes(coord1D, coord2D))
plot_result_per3 <- plot_result_per3 + ylim(-1,1) + xlim(-1,1)
plot_result_per3 <- plot_result_per3 + geom_point(aes(shape = party), size = 2)
plot_result_per3 <- plot_result_per3 + labs(y = "Dimension 2", x = "Dimension 1", title = "2002-2006 all votes")
plot_result_per3 <- plot_result_per3 + scale_shape_manual(values = c(0, 1, 2, 3, 4, 13, 10, 15, 12, 5, 14, 6, 7, 9, 8), 
                                                          drop = FALSE)
plot_result_per3 <- plot_result_per3 + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per3

plot_result_per4 <- ggplot(data = data_result_per4, aes(coord1D, coord2D))
plot_result_per4 <- plot_result_per4 + ylim(-1,1) + xlim(-1,1)
plot_result_per4 <- plot_result_per4 + geom_point(aes(shape = party), size = 2)
plot_result_per4 <- plot_result_per4 + labs(y = "Dimension 2", x = "Dimension 1", title = "2006-2010 all votes")
plot_result_per4 <- plot_result_per4 + scale_shape_manual(values = c(1, 2, 5, 6, 7, 9, 8))
plot_result_per4 <- plot_result_per4 + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per4

plot_result_per5 <- ggplot(data = data_result_per5, aes(coord1D, coord2D))
plot_result_per5 <- plot_result_per5 + ylim(-1,1) + xlim(-1,1)
plot_result_per5 <- plot_result_per5 + geom_point(aes(shape = party), size = 2)
plot_result_per5 <- plot_result_per5 + scale_shape_manual(values = c(2, 10, 12, 5, 6, 9, 8))
plot_result_per5 <- plot_result_per5 + labs(y = "Dimension 2", x = "Dimension 1", title = "2010-2012 all votes")
plot_result_per5 <- plot_result_per5 + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))

plot_result_per6 <- ggplot(data = data_result_per6, aes(coord1D, coord2D))
plot_result_per6 <- plot_result_per6 + ylim(-1,1) + xlim(-1,1)
plot_result_per6 <- plot_result_per6 + geom_point(aes(shape = party), size = 2)
plot_result_per6 <- plot_result_per6 + scale_shape_manual(values = c(2, 10, 15, 12, 5, 6, 8))
plot_result_per6 <- plot_result_per6 + labs(y = "Dimension 2", x = "Dimension 1", title = "2012-2016 all votes")
plot_result_per6 <- plot_result_per6 + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per6

plot_result_per7 <- ggplot(data = data_result_per7, aes(coord1D, coord2D))
plot_result_per7 <- plot_result_per7 + ylim(-1,1) + xlim(-1,1)
plot_result_per7 <- plot_result_per7 + geom_point(aes(shape = party), size = 2)
plot_result_per7 <- plot_result_per7 + scale_shape_manual(values = c(13, 10, 15, 12, 14, 6, 9, 8))
plot_result_per7 <- plot_result_per7 + labs(y = "Dimension 2", x = "Dimension 1", title = "2016-2019 all votes")
plot_result_per7 <- plot_result_per7 + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per7

plot_result_per3_rat <- ggplot(data = data_result_per3_rat, aes(coord1D, coord2D))
plot_result_per3_rat <- plot_result_per3_rat + ylim(-1,1) + xlim(-1,1)
plot_result_per3_rat <- plot_result_per3_rat + geom_point(aes(shape = party), size = 2)
plot_result_per3_rat <- plot_result_per3_rat + labs(y = "Dimension 2", x = "Dimension 1", title = "2002-2006 ratification votes")
plot_result_per3_rat <- plot_result_per3_rat + scale_shape_manual(values = c(0, 1, 2, 3, 4, 5, 6, 7, 8))
plot_result_per3_rat <- plot_result_per3_rat + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per3_rat

plot_result_per4_rat <- ggplot(data = data_result_per4_rat, aes(coord1D, coord2D))
plot_result_per4_rat <- plot_result_per4_rat + ylim(-1,1) + xlim(-1,1)
plot_result_per4_rat <- plot_result_per4_rat + geom_point(aes(shape = party), size = 2)
plot_result_per4_rat <- plot_result_per4_rat + labs(y = "Dimension 2", x = "Dimension 1", title = "2006-2010 ratification votes")
plot_result_per4_rat <- plot_result_per4_rat + scale_shape_manual(values = c(1, 2, 5, 6, 7, 9, 8))
plot_result_per4_rat <- plot_result_per4_rat + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per4_rat

plot_result_per5_rat <- ggplot(data = data_result_per5_rat, aes(coord1D, coord2D))
plot_result_per5_rat <- plot_result_per5_rat + ylim(-1,1) + xlim(-1,1)
plot_result_per5_rat <- plot_result_per5_rat + geom_point(aes(shape = party), size = 2)
plot_result_per5_rat <- plot_result_per5_rat + labs(y = "Dimension 2", x = "Dimension 1", title = "2010-2012 ratification votes")
plot_result_per5_rat <- plot_result_per5_rat + scale_shape_manual(values = c(2, 10, 12, 5, 6, 9, 8))
plot_result_per5_rat <- plot_result_per5_rat + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per5_rat

plot_result_per6_rat <- ggplot(data = data_result_per6_rat, aes(coord1D, coord2D))
plot_result_per6_rat <- plot_result_per6_rat + ylim(-1,1) + xlim(-1,1)
plot_result_per6_rat <- plot_result_per6_rat + geom_point(aes(shape = party), size = 2)
plot_result_per6_rat <- plot_result_per6_rat + labs(y = "Dimension 2", x = "Dimension 1", title = "2012-2016 ratification votes")
plot_result_per6_rat <- plot_result_per6_rat + scale_shape_manual(values = c(2, 10, 15, 12, 5, 6, 8))
plot_result_per6_rat <- plot_result_per6_rat + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per6_rat

plot_result_per7_rat <- ggplot(data = data_result_per7_rat, aes(coord1D, coord2D))
plot_result_per7_rat <- plot_result_per7_rat + ylim(-1,1) + xlim(-1,1)
plot_result_per7_rat <- plot_result_per7_rat + geom_point(aes(shape = party), size = 2)
plot_result_per7_rat <- plot_result_per7_rat + labs(y = "Dimension 2", x = "Dimension 1", title = "2016-2019 ratification votes")
plot_result_per7_rat <- plot_result_per7_rat + scale_shape_manual(values = c(13, 10, 15, 12, 14, 6, 9, 8))
plot_result_per7_rat <- plot_result_per7_rat + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per7_rat

combined_plot <- ggarrange(plot_result_per3, plot_result_per3_rat, plot_result_per4, plot_result_per4_rat, plot_result_per5, plot_result_per5_rat,
                           plot_result_per6, plot_result_per6_rat, plot_result_per7, plot_result_per7_rat,
                           common.legend = TRUE, legend = "bottom", ncol = 2, nrow = 5)


tiff("Figure 1 BW.tiff", units="in", width=10, height=15, res=300)
combined_plot
dev.off()


# plot in color

plot_result_per3_col <- ggplot(data = data_result_per3, aes(coord1D, coord2D))
plot_result_per3_col <- plot_result_per3_col + ylim(-1,1) + xlim(-1,1)
plot_result_per3_col <- plot_result_per3_col + geom_point(aes(color = party), size = 2)
plot_result_per3_col <- plot_result_per3_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2002-2006 all votes")
plot_result_per3_col <- plot_result_per3_col + scale_color_manual(values = c("yellow", "firebrick", "darkblue", "darkgreen", 
                                                                             "purple", "forestgreen", "coral", "goldenrod", 
                                                                             "green", "deepskyblue", "slateblue1", "red", 
                                                                             "orange", "black", "grey"), 
                                                                  drop = FALSE)
plot_result_per3_col <- plot_result_per3_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per3_col

plot_result_per4_col <- ggplot(data = data_result_per4, aes(coord1D, coord2D))
plot_result_per4_col <- plot_result_per4_col + ylim(-1,1) + xlim(-1,1)
plot_result_per4_col <- plot_result_per4_col + geom_point(aes(color = party), size = 2)
plot_result_per4_col <- plot_result_per4_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2006-2010 all votes")
plot_result_per4_col <- plot_result_per4_col + scale_color_manual(values = c("firebrick", "darkblue","deepskyblue",
                                                                             "red", "orange","black", "grey"))
plot_result_per4_col <- plot_result_per4_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per4_col

plot_result_per5_col <- ggplot(data = data_result_per5, aes(coord1D, coord2D))
plot_result_per5_col <- plot_result_per5_col + ylim(-1,1) + xlim(-1,1)
plot_result_per5_col <- plot_result_per5_col + geom_point(aes(color = party), size = 2)
plot_result_per5_col <- plot_result_per5_col + scale_color_manual(values = c("darkblue","coral","green", 
                                                                             "deepskyblue", "red", "black", "grey"))
plot_result_per5_col <- plot_result_per5_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2010-2012 all votes")
plot_result_per5_col <- plot_result_per5_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per5_col

plot_result_per6_col <- ggplot(data = data_result_per6, aes(coord1D, coord2D))
plot_result_per6_col <- plot_result_per6_col + ylim(-1,1) + xlim(-1,1)
plot_result_per6_col <- plot_result_per6_col + geom_point(aes(color = party), size = 2)
plot_result_per6_col <- plot_result_per6_col + scale_color_manual(values = c("darkblue", "coral", "goldenrod",
                                                                             "green", "deepskyblue", "red", "grey"))
plot_result_per6_col <- plot_result_per6_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2012-2016 all votes")
plot_result_per6_col <- plot_result_per6_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per6_col

plot_result_per7_col <- ggplot(data = data_result_per7, aes(coord1D, coord2D))
plot_result_per7_col <- plot_result_per7_col + ylim(-1,1) + xlim(-1,1)
plot_result_per7_col <- plot_result_per7_col + geom_point(aes(color = party), size = 2)
plot_result_per7_col <- plot_result_per7_col + scale_color_manual(values = c("forestgreen", "coral",  "goldenrod", 
                                                                             "green", "slateblue1", "red", "black", "grey"))
plot_result_per7_col <- plot_result_per7_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2016-2019 all votes")
plot_result_per7_col <- plot_result_per7_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per7_col

plot_result_per3_rat_col <- ggplot(data = data_result_per3_rat, aes(coord1D, coord2D))
plot_result_per3_rat_col <- plot_result_per3_rat_col + ylim(-1,1) + xlim(-1,1)
plot_result_per3_rat_col <- plot_result_per3_rat_col + geom_point(aes(color = party), size = 2)
plot_result_per3_rat_col <- plot_result_per3_rat_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2002-2006 ratification votes")
plot_result_per3_rat_col <- plot_result_per3_rat_col + scale_color_manual(values = c("yellow", "firebrick", "darkblue", "darkgreen",
                                                                                     "purple", "deepskyblue", 
                                                                                     "red", "orange", "grey"))
plot_result_per3_rat_col <- plot_result_per3_rat_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per3_rat_col

plot_result_per4_rat_col <- ggplot(data = data_result_per4_rat, aes(coord1D, coord2D))
plot_result_per4_rat_col <- plot_result_per4_rat_col + ylim(-1,1) + xlim(-1,1)
plot_result_per4_rat_col <- plot_result_per4_rat_col + geom_point(aes(color = party), size = 2)
plot_result_per4_rat_col <- plot_result_per4_rat_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2006-2010 ratification votes")
plot_result_per4_rat_col <- plot_result_per4_rat_col + scale_color_manual(values = c("firebrick", "darkblue","deepskyblue",
                                                                                     "red", "orange","black", "grey"))
plot_result_per4_rat_col <- plot_result_per4_rat_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per4_rat_col

plot_result_per5_rat_col <- ggplot(data = data_result_per5_rat, aes(coord1D, coord2D))
plot_result_per5_rat_col <- plot_result_per5_rat_col + ylim(-1,1) + xlim(-1,1)
plot_result_per5_rat_col <- plot_result_per5_rat_col + geom_point(aes(color = party), size = 2)
plot_result_per5_rat_col <- plot_result_per5_rat_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2010-2012 ratification votes")
plot_result_per5_rat_col <- plot_result_per5_rat_col + scale_color_manual(values = c("darkblue","coral","green", 
                                                                                     "deepskyblue", "red", "black", "grey"))
plot_result_per5_rat_col <- plot_result_per5_rat_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per5_rat_col

plot_result_per6_rat_col <- ggplot(data = data_result_per6_rat, aes(coord1D, coord2D))
plot_result_per6_rat_col <- plot_result_per6_rat_col + ylim(-1,1) + xlim(-1,1)
plot_result_per6_rat_col <- plot_result_per6_rat_col + geom_point(aes(color = party), size = 2)
plot_result_per6_rat_col <- plot_result_per6_rat_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2012-2016 ratification votes")
plot_result_per6_rat_col <- plot_result_per6_rat_col + scale_color_manual(values = c("darkblue", "coral", "goldenrod",
                                                                                     "green", "deepskyblue", "red", "grey"))
plot_result_per6_rat_col <- plot_result_per6_rat_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per6_rat_col

plot_result_per7_rat_col <- ggplot(data = data_result_per7_rat, aes(coord1D, coord2D))
plot_result_per7_rat_col <- plot_result_per7_rat_col + ylim(-1,1) + xlim(-1,1)
plot_result_per7_rat_col <- plot_result_per7_rat_col + geom_point(aes(color = party), size = 2)
plot_result_per7_rat_col <- plot_result_per7_rat_col + labs(y = "Dimension 2", x = "Dimension 1", title = "2016-2019 ratification votes")
plot_result_per7_rat_col <- plot_result_per7_rat_col + scale_color_manual(values = c("forestgreen", "coral",  "goldenrod", 
                                                                                     "green", "slateblue1", "red", "black", "grey"))
plot_result_per7_rat_col <- plot_result_per7_rat_col + theme_minimal() + theme(plot.margin = unit(c(1,1,1,1), "lines"))+ theme(plot.title = element_text(hjust = 0.5, face = "bold"))
plot_result_per7_rat_col


combined_plot <- ggarrange(plot_result_per3_col, plot_result_per3_rat_col, plot_result_per4_col, plot_result_per4_rat_col, plot_result_per5_col, plot_result_per5_rat_col,
                           plot_result_per6_col, plot_result_per6_rat_col, plot_result_per7_col, plot_result_per7_rat_col,
                           common.legend = TRUE, legend = "bottom", ncol = 2, nrow = 5)


tiff("Figure 1 COL.tiff", units="in", width=10, height=15, res=300)
combined_plot
dev.off()
